package com.hkfrich.system.service.impl;


import com.hkfrich.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkfrich.common.utils.SecurityUtils;
import com.hkfrich.generator.utils.DictUtils;
import com.hkfrich.system.domain.SysDictData;
import com.hkfrich.system.mapper.SysDictDataMapper;
import com.hkfrich.system.service.SysDictDataService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;


/**
 * 字典数据Service业务层处理
 * 
 * @author _Heishuai
 * @date 2022-09-15 00:08:52
 */
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements SysDictDataService {

    @Resource
    private SysDictDataMapper sysDictDataMapper;


    @Override
    public List<SysDictData> selectDictDataByType(String dictType) {
        return sysDictDataMapper.selectDictDataByType(dictType);
    }

    @Override
    public void deleteDictDataByIds(List<Long> list) {
        for (Long dictCode : list)
        {
            SysDictData data = sysDictDataMapper.selectById(dictCode);
            sysDictDataMapper.deleteById(dictCode);
            List<SysDictData> dictDatas = sysDictDataMapper.selectDictDataByType(data.getDictType());
            DictUtils.setDictCache(data.getDictType(), dictDatas);
        }
    }

    @Override
    public int updateDictData(SysDictData sysDictData) {
        int row = sysDictDataMapper.updateById(sysDictData);
        if (row > 0)
        {
            List<SysDictData> dictDatas = sysDictDataMapper.selectDictDataByType(sysDictData.getDictType());
            DictUtils.setDictCache(sysDictData.getDictType(), dictDatas);
        }
        return row;
    }
}
